package com.os.user.service.impl;

import com.os.user.dao.UserMapper;
import com.os.user.bean.User;
import com.os.user.service.UserService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.annotation.Resource;
import java.util.List;

/**
 * @author 
 * @version v1.0.0
 * @description User 实现类
 * @date Created in 2018-08-26 22:34:03
 */
@Service
@Transactional
public class UserServiceImpl implements UserService {

    private static final Logger LOGGER = LoggerFactory.getLogger(UserServiceImpl.class);

    @Resource
    private UserMapper userMapper;

    /**
     * 通过ID查找对象
     * @param userId
     * @return
     */
    @Override
    public User getById(Integer userId) throws Exception {
        return this.userMapper.getById(userId);
    }

    /**
     * 列表
     * @param
     * @return
     */
    @Override
    public List<User> list(User user) throws Exception {
		List<User> list = userMapper.list(user);
		return list;
	}

    /**
     * 删除
     * @param userId
     * @return
     */
	@Override
	public int deleteById(Integer userId) throws Exception {
		userMapper.deleteById(userId);
		return 1;
	}

    /**
     * 保存
     * @param user
     * @return
     */
	@Override
	public User save(User user) throws Exception {
		try {
            userMapper.save(user);
		}catch (Exception e){
			e.printStackTrace();
		}
		return user;
	}

    /**
     * 更新
     * @param user
     * @return
     */
	@Override
	public User update(User user) throws Exception {
		try {
            userMapper.update(user);
		}catch (Exception e){
			e.printStackTrace();
		}
		return user;
	}



}
